import java.util.Stack;

class MinStack {

    public Stack<Integer> stack;
    public Stack<Integer> Min;

    public MinStack() {
        stack = new Stack<>();
        Min = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if (Min.empty() || val <= Min.peek()) {
            Min.push(val);
        }
    }

    public void pop() {
        if (Min.peek().equals(stack.peek())) {
            Min.pop();
            stack.pop();
        } else {
            stack.pop();
        }
    }

    public int top() {
        if (stack.empty()) {
            return -1;
        }
        return stack.peek();
    }

    public int getMin() {
        return Min.peek();
    }
}
